<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击</button>
    <script>
        const button = document.querySelector('button')
        // button.onclick = () => {
        //     const xhr = new XMLHttpRequest()
        //     xhr.open('GET', 'http://192.168.22.24:4000/ping')
        //     xhr.send()
        //     xhr.onreadystatechange = () => {
        //         if (xhr.readyState === 4) {
        //             if (xhr.status === 200) {
        //                 console.log(123)
        //             } else {
        //                 console.log(456)
        //             }
        //         }
        //     }
        // }

        button.onclick = () => {
            const xhr = new XMLHttpRequest()
            xhr.open('POST', 'http://192.168.22.24:4000/ping')
            xhr.setRequestHeader('content-type', 'application/json')
            xhr.send(
                JSON.stringify({

                })
            )
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        console.log(123)
                    } else {
                        console.log(456)
                    }
                }
            }
        }
    </script>
</body>

</html>